#include "movieDetailMessage.h"
#include "jsonUtils.h"

MovieDetailMessage::MovieDetailMessage(MtpProtocol* packet) : MtpMessage(packet), movieId(0)
{

}

MovieDetailMessage::MovieDetailMessage(int64_t movieId) : MtpMessage(new MtpProtocol(L"movieDetail")) , movieId(movieId)
{

}

void MovieDetailMessage::decodeBody()
{
    MtpMessage::decodeBody();
    if (!jsonContent.empty()) {
        JsonDoc doc;
        doc.Parse(jsonContent.c_str());
        JsonUtils::loadLong(doc, L"movieId", movieId);
    }
}

void MovieDetailMessage::encodeBody()
{
    JsonDoc doc;
    doc.SetObject();
    doc.AddMember(L"movieId", movieId, doc.GetAllocator());
    jsonContent = JsonUtils::jsonStr(doc);
    MtpMessage::encodeBody();
}

const int64_t& MovieDetailMessage::getMovieId()
{
    return movieId;
}
